package com.wind.plugin.config;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@State(name = "CurrencySettings",
        storages = @Storage("currencySettings.xml"))
public final class CurrencySettings implements PersistentStateComponent<CurrencySettings> {

    private List<String> currencyKeywords = new ArrayList<>(Arrays.asList("CUR", "curr", "currencyCode", "NBCBCURCODE", "CURRENCY_ID"));


    // 获取当前的配置
    public List<String> getCurrencyKeywords() {
        return currencyKeywords;
    }

    // 设置新的配置
    public void setCurrencyKeywords(List<String> currencyKeywords) {
        this.currencyKeywords = currencyKeywords;
    }

    @Override
    public @NotNull CurrencySettings getState() {
        return this;
    }

    @Override
    public void loadState(@NotNull CurrencySettings state) {
        this.currencyKeywords = state.currencyKeywords;
    }

    public static CurrencySettings getInstance() {
        return ApplicationManager.getApplication().getComponent(CurrencySettings.class);
    }

    public void addCurrencyKeyword(String keyword) {
        if (keyword != null && !keyword.trim().isEmpty() && !currencyKeywords.contains(keyword)) {
            currencyKeywords.add(keyword);
        }
    }

    public void removeCurrencyKeyword(String keyword) {
        currencyKeywords.remove(keyword);
    }

}
